import 'package:flutter/material.dart';

class CnMessageItemView extends StatefulWidget {
  final String text;
  final String photo;
  final Function() trDoneCallBack;

  const CnMessageItemView(this.photo, this.text, this.trDoneCallBack,
      {super.key});

  @override
  State<StatefulWidget> createState() => MessageItemState();
}

class MessageItemState extends State<CnMessageItemView>
    with AutomaticKeepAliveClientMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
              padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 8),
              decoration: const BoxDecoration(
                  color: Colors.black45,
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(10),
                      topRight: Radius.circular(10),
                      bottomLeft: Radius.circular(10),
                      bottomRight: Radius.circular(10))),
              child: Row(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    ClipRRect(
                        borderRadius: BorderRadius.circular(60),
                        child: Image.network(widget.photo,
                            height: 30,
                            width: 30,
                            fit: BoxFit.cover, loadingBuilder: (
                          BuildContext context,
                          Widget child,
                          ImageChunkEvent? loadingProgress,
                        ) {
                          if (loadingProgress == null) {
                            return child;
                          } else {
                            return Image.asset(
                              'images/ic_placeholder.webp',
                              width: 30,
                              height: 30,
                            );
                          }
                        }, errorBuilder: (BuildContext context, Object error,
                                StackTrace? stackTrace) {
                          return Image.asset(
                            'images/ic_placeholder.webp',
                            width: 30,
                            height: 30,
                          );
                        })),
                    const SizedBox(width: 10),
                    ConstrainedBox(
                      constraints: const BoxConstraints(maxWidth: 180),
                      child: Text(widget.text,
                          style: const TextStyle(
                              color: Color(0xfff8F8FA), fontSize: 15)),
                    )
                  ]))
        ]);
  }

  @override
  bool get wantKeepAlive => true;
}
